﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>选择岗位</title>
	 <link href="../Comm/Style/CommStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet"  type="text/css" />
    <link href="../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script src="../Scripts/EasyUIUtility.js" type="text/javascript"></script>

	<base target="_self" />
	<script type="text/javascript">

	    //页面启动函数.
        var data;
	    $(function () {
	        $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

	        //求出来已经设置的延续子流程.
	        var nodeID = GetQueryString("FK_Node");
	        var orgNo = GetQueryString("OrgNo");
	        if (orgNo == null || orgNo == undefined)
	            orgNo = 0;

	        //获得该组织的岗位.
	        var stas = new Entities("BP.Port.Stations");
	        stas.Retrieve("OrgNo", orgNo);

            var stationTypes = new Entities("BP.WF.Port.StationTypes");
	        data = stationTypes.DoMethodReturnString("GetStationTypes", orgNo);
            data = JSON.parse(data);
	       
	        BindGroupModel(data, stas);

	    });

	    function BindGroupModel(groups, stas) {

	        AttrOfMInMM = "FK_Station";
	        var html = "<table style='width:100%;' >";

	        html += "<tr>";
	        html += "<th colspan=3>";
	        html += "<div style='float:left'>";
            html += "<input type=button value='确定' onclick='SelectStas();' id='save' />";
             html += "<input type=button value='取消' onclick='Close();' id='save' />";
	        html += "</div>";

	        html += "</th>";
	        html += "</tr>";

	        for (var i = 0; i < groups.length; i++) {

	            var group = groups[i];

	            html += "<tr>";
	            html += "<th colspan=3>";

	            html += "<input type='checkbox'  onclick='CheckAll(this.checked, \"" + group.No + "\");' id='Group_" + group.No + "'  /><label for='Group_" + group.No + "'>" + group.Name + "</label>";

	            html += "</th>";
	            html += "</tr>";


	            var myNum = -1;
	            for (var idx = 0; idx < stas.length; idx++) {

	                en = stas[idx];

	                var myidx = 0;
	                var oOfEn;
	                for (var obj in en) {
	                    if (myidx == 2) {
	                        oOfEn = obj;
	                        break;
	                    }
	                    myidx++;
	                }

	                myidx = 0;
	                var oOfGroup;
	                for (var obj in en) {
	                    if (myidx == 0) {
	                        oOfGroup = obj;
	                        break;
	                    }
	                    myidx++;
	                }
	                if (en[oOfEn] != group[oOfGroup])
	                    continue;
	                var lab = en.Name;
	                myNum++;
	                if (myNum == 0)
	                    html += "<TR>";
	                html += "<td><input type='checkbox'  name='" + group.No + "' id='CB_" + en.No + "' value='" + en.No + "' /><label for='CB_" + en.No + "'>" + lab + "</label></td>";
	                if (myNum == 2) {
	                    html += "</tr>";
	                    myNum = -1;
	                }
	            }

	            if (idx == 1) {
	                html += "<td colspan=2></td>";
	                html += "</tr>";
	            }

	            if (idx == 2) {
	                html += "<td></td>";
	                html += "</tr>";
	            }
	        }

	        html += "</table>";
	        $("#Msg").html("");
	        $("#Msg").html(html);
	    }

	    //选择与取消选择.
	    function CheckAll(checked, no) {

	        $("input[name='" + no + "']").each(function () {
	            this.checked = checked;
	        });

	    }

        //取消岗位选择
        function Close() {
            if (window.parent != null && window.parent.selectEmpsWindowClose != null) {
                window.parent.selectStasWindowClose("取消");
            }
        }

        //保存.
        var returnVal=[]
        function SelectStas() {
            //获取选择的岗位
            for (var i = 0; i < data.length; i++) {
                $.each($('input:checkbox[name='+data[i].No+']:checked'),function(i,obj){
                    returnVal.push({ "No": obj.value, "Name": $(obj).next().text() });
             });
            }
            //No  是返回到别的页面的值
            if (returnVal.length==0) {
                alert("未选择人员");
            } else {
                window.parent.selectStasWindowClose("确定");
            }
	    }

    </script>
</head>
<body>


    <div id="Msg"></div>
</body>
</html>
